export class TestForm {
  constructor() {
    this.cache = ''
  }
  testVal(val, rules) {
    for (let i = 0, rule; rule = rules[i++];) {
      if (this.theRules[rule.methodName](val, rule.errMsg, rule.length)) {
        this.cache = rule.errMsg
      }
    }
  }
  start() {
    if (this.cache) {
      return this.cache
    }
  }
  theRules = {
    //校验手机号
    isPhone(val, errMsg) {
      let reg = /^((13[0-9])|(14[5-9])|(15([0-3]|[5-9]))|(16[6])|(17[1-8])|(18[0-9])|(19[8-9]))\d{8}$/g;
      if (!reg.test(val)) {
        return errMsg;
      }
    },
    //判断不能为空
    isNull(val, errMsg) {
      if (!val) {
        return errMsg;
      }
    }
  }
}